ref(node): Move node-fetch instrumentation away from InstrumentBase#21778
ref(node): Move node-fetch instrumentation away from InstrumentBase#21778mydea wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit cc1a55a. Configure here.
size-limit report 📦
|
| breadcrumbs?: boolean; | ||
|
|
||
| /** | ||
| * If set to false, do not emit any spans. | ||
| * This will ensure that the default UndiciInstrumentation from OpenTelemetry is not setup, | ||
| * only the Sentry-specific instrumentation for breadcrumbs & trace propagation is applied. |
There was a problem hiding this comment.
Bug: The tracePropagation: false option is ignored by the new instrumentUndici function, causing trace headers to be injected unconditionally for span instrumentation.
Severity: MEDIUM
Suggested Fix
Update the UndiciInstrumentationConfig type to include the tracePropagation option. Pass this option from the nativeNodeFetchIntegration options into instrumentUndici(). Finally, modify instrumentUndici() and its helper injectTracePropagationHeaders() to respect the tracePropagation flag and only inject headers when it is not false.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: packages/node/src/integrations/node-fetch/index.ts#L27-L32
Potential issue: The new undici span instrumentation does not honor the
`tracePropagation: false` option. The `instrumentUndici()` function, which handles span
instrumentation, is called without the `tracePropagation` option and has no mechanism to
receive it. As a result, its internal `injectTracePropagationHeaders()` function is
always called, leading to trace headers being unconditionally injected for outgoing
requests when spans are enabled. This is a regression from previous behavior where the
option was respected, and it contradicts the user's explicit configuration.
Also affects:
packages/node/src/integrations/node-fetch/undici-instrumentation.ts:385~411
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
clarified the comment for this
| function safeExecute<T>(fn: () => T, onError: (error: unknown) => void): T | undefined { | ||
| try { | ||
| return fn(); | ||
| } catch (error) { | ||
| onError(error); | ||
| return undefined; | ||
| } | ||
| } |
There was a problem hiding this comment.
q: Could we extract that into a common helper? We also use this in the aws lambda instrumentation.
There was a problem hiding this comment.
possibly, but also not 100% sure, I think realistically most of this usage should actually go away, this is just for user provided callbacks really, not sure how many of these we'll still need in v11...?

This streamlines and de-otelifies the undici instrumentation in node package.
Note that there is still a OTEL instrumentation (channel based, but still) in node-core which can be updated in a separate follow up step.
This also updates to use sentry/conventions and drop any config we hard coded so far, streamlining this. Also, unsubscribe code was removed and other things we do not need were removed.